<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${mapperInterface.packageName}.${baseInfo.fileName}">

    <resultMap id="BaseResultMap" type="${tableClass.fullClassName}">
        <#list tableClass.pkFields as field>
            <id property="${field.fieldName}" column="${field.columnName}" jdbcType="${field.jdbcType}"/>
        </#list>
        <#list tableClass.baseFields as field>
            <result property="${field.fieldName}" column="${field.columnName}" jdbcType="${field.jdbcType}"/>
        </#list>
    </resultMap>

    <sql id="column_list">
        <#list tableClass.allFields as field>${field.columnName}<#sep>, <#if field_index%7==6>${"\n        "}</#if></#list>
    </sql>

    <sql id="table_name">
        ${tableClass.tableName}
    </sql>

    <insert id="insert" parameterType="${tableClass.fullClassName}">
        insert into <include refid="table_name" />
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <#list tableClass.allFields as field>
                <if test="${field.fieldName} != null">${field.columnName},</if>
                </#list>
            </trim>
        values
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <#list tableClass.allFields as field>
                <if test="${field.fieldName} != null">${'#'}{${field.fieldName}, jdbcType=${field.jdbcType}},</if>
                </#list>
            </trim>
    </insert>

    <delete id="delete" parameterType="${tableClass.fullClassName}">
        delete from <include refid="table_name" />
        <where>
            <#list tableClass.allFields as field>
            <if test="${field.fieldName} != null">${field.columnName} = ${'#'}{${field.fieldName}, jdbcType=${field.jdbcType}} and</if>
            </#list>
        </where>
    </delete>

    <update id="updateById" parameterType="${tableClass.fullClassName}">
        update <include refid="table_name" />
        <set>
            <#list tableClass.baseFields as field>
            <if test="${field.fieldName} != null">${field.columnName} = ${'#'}{${field.fieldName}, jdbcType=${field.jdbcType}},</if>
            </#list>
        </set>
        <where>
            <#list tableClass.pkFields as field>
            <if test="${field.fieldName} != null">${field.columnName} = ${'#'}{${field.fieldName}, jdbcType=${field.jdbcType}}</if>
            </#list>
        </where>
    </update>

    <select id="selectAll" resultType="${tableClass.fullClassName}">
        select
            <include refid="column_list" />
        from
            <include refid="table_name" />
    </select>
</mapper>
